package dangs.controller;


import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import dangs.dao.LocationDAO;
import dangs.vo.LocationVO;

public class LocationController extends MultiActionController {
	private LocationDAO locationDAO;
	private LocationVO lvo;

	public LocationController(){}
	public void setLocationDAO(LocationDAO locationDAO) {
		this.locationDAO = locationDAO;
	}
	

	public void setLocationVO(LocationVO lvo) {
		this.lvo = lvo;
	}
	
	 public ModelAndView locationRegister(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 return new ModelAndView("register_location");
	 }
	 
	 public ModelAndView locationList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 ArrayList list = locationDAO.selectAllLocation();
		 return new ModelAndView("select_all_location", "list", list);
	 }
	 
	public ModelAndView registerLocation(HttpServletRequest request, HttpServletResponse response, LocationVO lvo) throws Exception{
			locationDAO.locationRegister(lvo);
			 ArrayList list = locationDAO.selectAllLocation();
			 return new ModelAndView("select_all_location", "list", list);
		}
	 public ModelAndView updateForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 String locationCode = request.getParameter("locationCode");
		 LocationVO lvo = locationDAO.selectByLocationId(locationCode);
		 return new ModelAndView("update_location", "lvo", lvo);
	 	}
	 public ModelAndView updateLocation(HttpServletRequest request, HttpServletResponse response, LocationVO lvo) throws Exception{
			locationDAO.updateLocation(lvo);
			 ArrayList list = locationDAO.selectAllLocation();
			 return new ModelAndView("select_all_location", "list", list);
	 	}
	 

	 public ModelAndView deleteByLocationId(HttpServletRequest request, HttpServletResponse response, LocationVO lvo) throws Exception{	
		 	locationDAO.deleteByLocationId(lvo);
		 	 ArrayList list = locationDAO.selectAllLocation();
			 return new ModelAndView("select_all_location", "list", list);
	 	}
	 
	 public ModelAndView selectByLocationId(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 String locationCode = request.getParameter("locationCode");
		 LocationVO lvo = locationDAO.selectByLocationId(locationCode);
		 return new ModelAndView("update_location", "lvo", lvo);
	 	}
}
